package com.itheima.pinda.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.itheima.pinda.DTO.base.GoodsTypeDto;
import com.itheima.pinda.common.utils.PageResponse;
import com.itheima.pinda.common.utils.Result;
import com.itheima.pinda.service.PdGoodsTypeService;
import com.itheima.pinda.util.ResultUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "货物类型管理")
@RestController
@RequestMapping(value = "base/goodsType")
public class PdGoodsTypeController {

    @Autowired
    private PdGoodsTypeService pdGoodsTypeService;

    @ApiOperation(value = "货物类型新增")
    @PostMapping(value = "/Add")
    public GoodsTypeDto goodsTypeAdd(GoodsTypeDto goodsTypeDto){

       return pdGoodsTypeService.goodsTypeAddOrUpdate(goodsTypeDto);
    }

    @ApiOperation(value = "根据id查询货物类型")
    @GetMapping(value = "/selectById")
    public GoodsTypeDto selectById(@RequestParam("id") String id) {
        return pdGoodsTypeService.selectById(id);
    }

    @ApiOperation(value = "查询所有货物类型")
    @PostMapping(value = "selectList")
    public List<GoodsTypeDto> selectList(){
        return pdGoodsTypeService.selectList();
    }

    @ApiOperation(value = "分页查询")
    @PostMapping(value = "/selectByPage")
    public PageResponse selectByPage(@RequestParam("pageNum") Integer pageNum,
                                     @RequestParam("pageSize") Integer pageSize,
                                     @RequestParam(value = "name",required = false)String name,
                                     @RequestParam(value = "truckTypeId",required = false) String truckTypeId,
                                     @RequestParam(value = "truckTypeName",required = false) String truckTypeName){
        IPage page = pdGoodsTypeService.selectByPage(pageNum, pageSize, name, truckTypeId, truckTypeName);

        return ResultUtils.pageResult(pageNum,pageSize,page);
    }

    @ApiOperation(value = "货物类型更新")
    @PostMapping(value = "/update")
    public GoodsTypeDto goodsTypeUpdate(GoodsTypeDto dto){

        return pdGoodsTypeService.goodsTypeAddOrUpdate(dto);
    }

    @ApiOperation(value = "货物类型删除")
    @DeleteMapping(value = "/delete")
    public Result goodsTypeDelete(@RequestBody() List<String> ids){

        pdGoodsTypeService.goodsTypeDelete(ids);
        return Result.ok("删除成功！");
    }
}
